/*2112Widget*/


YAHOO.widget._2112SnapInPanel_ = function(el, userConfig) {

               if (arguments.length > 0) {
                  this.WindowName = el ;                   
						YAHOO.widget._2112SnapInPanel_.superclass.constructor.call(this, el, userConfig);                  
					}
          //the widgets position
               
               this.unload = function(){} ; //OVERRIDE this method to unload your SnapIn
               this.drop = function() {} ;

               this.getWindowExtY = function()
               {

                  if( YAHOO.util.Event.isIE )
                     return  this.header.offsetHeight + this.body.children[0].offsetHeight + this.footer.offsetHeight + 16 ;
                  else 
                     return  this.body.firstChild.clientHeight + this.header.clientHeight + this.footer.clientHeight + 8 ;
//

                    

               }

               this.getBodyHeight = function()
               {
                  if( YAHOO.util.Event.isIE )
                     return  this.body.children[0].offsetHeight ;
                  else 
                     return this.body.firstChild.clientHeight
               }

               this.calcBodyHeight = function(iSnapInTargetHeight)
               {  //border = 4


//alert(iSnapInTargetHeight + "/" + this.header.clientHeight + "/" +  this.footer.clientHeight) ;

                  if( YAHOO.util.Event.isIE )
                     return  iSnapInTargetHeight -  (4 + this.header.offsetHeight + this.footer.offsetHeight) ;
                  else                    
                     return iSnapInTargetHeight -   (12 + this.header.clientHeight + this.footer.clientHeight ); 
               }
               

            this.beforeHideEvent.subscribe(function() {                        
                        this.unload(this.WindowName) ;                     
                    }, this, true);
     

}
YAHOO.extend(YAHOO.widget._2112SnapInPanel_, YAHOO.widget.Panel);

onSnapInLoaded = function(myPanel)
{
  //Workaround: Firefox will show double scrollbars till Framewidth is set properly
  if( YAHOO.util.Event.isIE ) return ;
 
	var myIFrame = document.getElementById(myPanel.WindowName + '_iFrame');
	if( myIFrame != null )
	{
      myIFrame.height  = '100%' ; 
		myIFrame.width  = '100%' ;  
	}
}


//theContent -> also used to host other resources (like a menubar);
//but would be HTML in most cases.
onSnapInAvail = function(myPanel, snapInID, theContent, myName, myTitle, 
                          strWidth, strHeight, bNoBounds) 
{ 
  myPanel.setHeader("<div class='tl'></div><span>" + myTitle + " </span><div class='tr'></div>");  

  //if(theContent.substr(0, 6) == '<embed')
  //theContent.replace(/>/g,"wmode=\"transparent\">") ;

  myPanel.setBody(theContent) ;     
  myPanel.setFooter("<div id=\"nls2112_ResizeFooter\"></div>"); 
 myPanel.render(document.body);  
  if( true == bNoBounds )
  {
    myPanel.body.style.overflow = 'visible' ;
    myPanel.footer.style.visibility = 'hidden' ;
  } 
  var headerHeight = myPanel.header.offsetHeight;
  var bodyHeight = myPanel.calcBodyHeight(parseInt(strHeight, 10)) ;   //( parseInt(strHeight, 10) - myPanel.footer.offsetHeight - myPanel.header.offsetHeight - 13);
 //alert(snapInID + " BodyHeight:  " + bodyHeight) ;
  if (bodyHeight < 0) {
			bodyHeight = 0;
  }

  myPanel.body.style.height = bodyHeight ; 
      
 
  myPanel.show() ;


}
 
//nobounds -> content may exceed bounds (like drop down menu)
initSnapIn = function (cbDrag, cbDrop, cbUnload, theContent, snapInID, strTitle, 
                        iPreferredWidth, unitW, iPreferredHeight, unitH, bNoBounds, bCanClose) { 
    
    

     var myPanel = 
	         new YAHOO.widget._2112SnapInPanel_(snapInID, 
         { iframe:false, position:"absolute",  width:iPreferredWidth + unitW, height: iPreferredHeight + unitH,                        
           close:bCanClose, visible:false, constraintoviewport:false } );
  
     myPanel.draggable = true ;                         
     myPanel.WindowName = snapInID ;
     
     //important: do the onPanelAvail before Repos (Header would not be set).
     myDiv = onSnapInAvail( myPanel, snapInID, theContent, snapInID, strTitle,  
                              iPreferredWidth, iPreferredHeight, bNoBounds) ; 
     //the unload Callback
     myPanel.unload = cbUnload;
     myPanel.drop = cbDrop ;
     myPanel.drag = cbDrag ;
     myPanel.dd.endDrag = function(e) {
            var dropx = e.clientX;  //savcopy
            var dropy = e.clientY;
            myPanel.syncPosition ( ) ;
            myPanel.drop(myPanel.WindowName, dropx, dropy, myPanel.body.clientWidth, myPanel.body.clientHeight) ; //which is not correct, since coordinates differ slightly
			   //alert(e.pageY + ' endDrag') ;
        };
     myPanel.dragEvent.subscribe(function(){             
           myPanel.drag() ; //which is not correct, since coordinates differ slightly         
}) ;


 


 	  onSnapInLoaded( myPanel) ;

     return myPanel ; //important, so SIMs could apply some logic to the Panel

}
